#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

/*
 * -1 treasure card from hand
 * +1 card into hand with cost >= 3
 */
mine_test()
{
	int i, j;
	int choice1, choice2;
	int prev_treasure_count;
	int prev_choice1_count;
	struct gameState state;

	init_test_date(&state, 1);

	srand(time(NULL));

	for (i = 0; i < MAX_ITERATIONS; i++) {
		state.deckCount[0] = 50;
		for (j = 0; j < state.deckCount[0]; j++) {
			state.deck[0][j] = random_card();
		}

		state.handCount[0] = 5;
		for (j = 0; j < 4; j++) {
			state.hand[0][j] = random_card();
		}
		state.hand[0][4] = mine;

		choice1 = rand() % 3;
		choice2 = random_card();

		if (treasure_count(state.hand[0], state.handCount[0]) == 0) {
			if (mine_effect(&state, 0, choice1, choice2, 4) != -1) {
				printf("FAIL: iteration %d - did not fail on lack of treasure card in hand.", i);
			}
		} else {
			prev_treasure_count = treasure_count(state.hand[0], state.handCount[0]);
			if (mine_effect(&state, 0, choice1, choice2, 4) != -1
				&& treasure_count(state.hand[0], state.handCount[0]) == prev_treasure_count) {
				printf("FAIL: iteration %d - did not fail on lack of -1 treasure cards.\n", i);
			}

			prev_choice1_count = card_count(state.hand[0], state.hand[0][choice1], state.handCount[0]);
			if (mine_effect(&state, 0, choice1, choice2, 4) != -1
				&& card_count(state.hand[0], choice1, state.handCount[0]) == prev_choice1_count) {
				printf("FAIL: iteration %d - did not trash choice1", i);
			}

			if (choice1 != copper && choice2 != silver && choice1 != gold
				&& mine_effect(&state, 0, choice1, choice2, 4) != -1) {
				printf("FAIL: iteration %d - did not fail on choice1 not being a treasure card.\n", i);
			}
		}
	}
}

int int main(int argc, char const *argv[])
{
	mine_test();
	return 0;
}